<template>
  <view class="container">
    <navbar :config="config" backColor="#000"></navbar>
	<!-- bg-fff -->
    <view class="u-mt20 u-p3040" v-for="(value,index) in goodsList" :key="value.id">
      <view class="goodsItem  u-flex-center" @click="goSalesReturn(value.id, value)">
        <image :src="value.goods_cover" v-if="value.goods_cover" class="u-goods200" mode=""></image>
        <image :src="value.goods_img" v-if="value.goods_img" class="u-goods200" mode=""></image>
        <view class="u-flex1 u-flex-column-start rightText u-ml30">
          <view class="u-display1 u-474747 u-font32 textWidth">{{value.goods_title}}</view>
          <view class="bottext u-flex-column-start u-flex1">
            <text class="u-font26 u-AAAAAA u-mt10" style="padding-right: 60rpx;" v-if="value.sku_set_name">规格： {{value.sku_set_name}}</text>
            <view class="u-flex-center botPrice u-mt30">
              <view class="u-FF0000 u-font32 ">
                <rich-text :nodes="$mUtil.priceBigSmall(value.sale_price)"></rich-text>
              </view>
              <text class="u-font26 u-666 u-ml15" v-if="value.num">x {{value.num}}</text>
              <text class="u-font26 u-666 u-ml15" v-if="value.number">x {{value.number}}</text>
            </view>
          </view>
          <view class="protect_rights">
            <text class="u-FF0000 u-font28" v-if="value.rights_type==1">
              仅退款 {{value.rights_status == '1' ? '维权中' : '完成'}}</text>
            <text class="u-FF0000 u-font28" v-if="value.rights_type==2">
              退货退款 {{value.rights_status == '1' ? '维权中' : '完成'}}</text>
          </view>
        </view>
        <view class="iconfont u-font36 u-999 blackPositin">&#xe6c7;</view>
      </view>
    </view>
	<view class="u-font28 u-474747">
	  <view class="u-flex-center-sb u-border-one-one u-p3040">
	    <view>订单编号</view>
	    <view class="u-font3">{{order_code}}</view>
	  </view>
	  <view class="u-flex-center-sb u-border-one-one  u-p3040">
	    <view>下单时间</view>
	    <view>{{format_order_time}}</view>
	  </view>
	</view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        config: {
		  back: true, //false是tolbar页面 是则不写
		  title: '申请售后',
		  color: '#000',
		  //背景颜色;参数一：透明度（0-1）;参数二：背景颜色（array则为线性渐变，string为单色背景）
		  backgroundColor: [1, "#fff"],
		  statusBarFontColor: '#1A1A1A',
		  backIconColor: "#000"
		  
		  
        },
        keystatus: 1, //1未发货，退款，2收到货退款/退货
        order_code: '',
        format_order_time: '',
        goodsList: [],
        orderid: null,
      }
    },
    filters: {
      payStatusRight(val) { //退款
        //维权订单操作状态（0申请，1同意，2买家已发货，3商家已收到退货商品,4商家发起退款支付，5已支付退款,6拒绝，7自动关闭,8主动撤消
        switch (val) {
          case 0:
            return "申请退款中"
            break;
          case 1:
            return "商家同意"
            break;
          case 4:
            return "商家发起退款支付"
            break;
          case 5:
            return "退款成功"
            break;
          case 6:
            return "商家拒绝"
            break;
          default:
            break;
        }
      },
      payStatusRights(val) { //退款退货
        //维权订单操作状态（0申请，1同意，2买家已发货，3商家已收到退货商品,4商家发起退款支付，5已支付退款,6拒绝，7自动关闭,8主动撤消
        switch (val) {
          case 0:
            return "申请退款/退货中"
            break;
          case 1:
            return "等待买家发货"
            break;
          case 2:
            return "待商家收货"
            break;
          case 3:
            return "商家已收货"
            break;
          case 4:
            return "商家待打款"
            break;
          case 5:
            return "退款/退货成功"
            break;
          case 6:
            return "商家拒绝"
            break;
          case 7:
            return "自动关闭"
            break;
          case 8:
            return "撤销"
            break;
          default:
            break;
        }
      }
    },
    onLoad(options) {
      if (options.keystatus) {
        this.keystatus = options.keystatus
      }
      if (options.order_code) {
        this.order_code = options.order_code
      }
      if (options.orderid) {
        this.orderid = options.orderid
      }
      if (options.childid && options.childid != 'undefined') {
        this.orderid = options.childid
      }
      if (options.format_order_time) {
        this.format_order_time = options.format_order_time
      }
      // let goodslist = uni.getStorageSync('blackgoodsList')
      // if (goodslist) {
      //   this.goodsList = goodslist
      // }
      this.$nextTick(() => {
        this.getOrderDetail()
      })
    },
    methods: {
      // 获取订单详情
      getOrderDetail() {
        this.$http.get(`/order/info/${this.orderid}`).then(res => {
          if (res.code == 200) {
            this.goodsList = res.data.child_order_list
          }
        })
      },
      //
      async goSalesReturn(id, item) {
        // if (item.third) {
        //   let res = await this.verify(item)
        //   if (!res) return this.$mUtil.toast('该商品不支持维权')
        // }
        if (item.rights_status == 1) return this.$mUtil.toast('维权中')
        let title = ''
        if (this.keystatus == 1) {
          title = "申请退款"
        } else {
          title = "申请退货退款"
        }
        uni.navigateTo({
          url: `applicationDrawback?title=${title}&id=${id}&keystatus=${this.keystatus}&orderid=${this.orderid}&third=${item.third}`
        })
      },
      // 第三方售后前置校验
      verify(item) {
        return new Promise((resolve, reject) => {
          this.$http.post('/rights/third/beforeCheck', {
            order_id: item.order_id,
            child_order_id: item.id
          }).then(res => {
            if (res.code == 200 && res.data) {
              if (res.data.serviceType.length > 0) {
                let isAfterSale = res.data.serviceType.some(item => item.code == '40' || item.code == '50')
                resolve(isAfterSale)
              }
            } else {
              resolve(false)
            }
          }).catch(err => {
            reject(false)
          })
        })
      }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #F5F5F5;
  }

  .textWidth {
    width: 400rpx;
  }

  .bg-fff {
    background-color: #fff;
  }

  .goodsItem {
    position: relative;
  }

  .blackPositin {
    position: absolute;
    top: 50%;
    right: 0;
    margin-top: -18rpx;
  }

  .protect_rights {
    width: 100%;
    text-align: right;
  }
</style>
